# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=pyqt6
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=6.9.0
pkgrel=1
pkgdesc="Python bindings for the Qt cross platform application toolkit (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://riverbankcomputing.com/software/pyqt"
msys2_references=(
  'purl: pkg:pypi/pyqt6'
)
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-pyqt6-sip"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-qt6-base")
optdepends=("${MINGW_PACKAGE_PREFIX}-qt6-activeqt"
            "${MINGW_PACKAGE_PREFIX}-qt6-connectivity"
            "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
            "${MINGW_PACKAGE_PREFIX}-qt6-multimedia"
            "${MINGW_PACKAGE_PREFIX}-qt6-pdf"
            "${MINGW_PACKAGE_PREFIX}-qt6-positioning"
            "${MINGW_PACKAGE_PREFIX}-qt6-quick3d"
            "${MINGW_PACKAGE_PREFIX}-qt6-remoteobjects"
            "${MINGW_PACKAGE_PREFIX}-qt6-scxml"
            "${MINGW_PACKAGE_PREFIX}-qt6-sensors"
            "${MINGW_PACKAGE_PREFIX}-qt6-serialport"
            "${MINGW_PACKAGE_PREFIX}-qt6-shadertools"
            "${MINGW_PACKAGE_PREFIX}-qt6-speech"
            "${MINGW_PACKAGE_PREFIX}-qt6-svg"
            "${MINGW_PACKAGE_PREFIX}-qt6-tools"
            "${MINGW_PACKAGE_PREFIX}-qt6-webchannel"
            "${MINGW_PACKAGE_PREFIX}-qt6-websockets")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-sip"
             "${MINGW_PACKAGE_PREFIX}-pyqt-builder"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-qt6-activeqt"
             "${MINGW_PACKAGE_PREFIX}-qt6-connectivity"
             "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
             "${MINGW_PACKAGE_PREFIX}-qt6-multimedia"
             $([[ ${MSYSTEM} == MINGW64 || ${CARCH} == aarch64 ]] || echo "${MINGW_PACKAGE_PREFIX}-qt6-pdf")
             "${MINGW_PACKAGE_PREFIX}-qt6-positioning"
             "${MINGW_PACKAGE_PREFIX}-qt6-quick3d"
             "${MINGW_PACKAGE_PREFIX}-qt6-remoteobjects"
             "${MINGW_PACKAGE_PREFIX}-qt6-scxml"
             "${MINGW_PACKAGE_PREFIX}-qt6-sensors"
             "${MINGW_PACKAGE_PREFIX}-qt6-serialport"
             "${MINGW_PACKAGE_PREFIX}-qt6-shadertools"
             "${MINGW_PACKAGE_PREFIX}-qt6-speech"
             "${MINGW_PACKAGE_PREFIX}-qt6-svg"
             "${MINGW_PACKAGE_PREFIX}-qt6-tools"
             "${MINGW_PACKAGE_PREFIX}-qt6-webchannel"
             "${MINGW_PACKAGE_PREFIX}-qt6-websockets")
source=(https://pypi.python.org/packages/source/P/PyQt6/pyqt6-${pkgver}.tar.gz)
sha256sums=('6a8ff8e3cd18311bb7d937f7d741e787040ae7ff47ce751c28a94c5cddc1b4e6')

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r PyQt6-${pkgver} python-build-${MSYSTEM}
}

build() {
  cd "${srcdir}"/python-build-${MSYSTEM}

  if check_option "debug" "n"; then
    _build_type=release
  else
    _build_type=debug
  fi

  MSYS2_ARG_CONV_EXCL="--api-dir=;" \
  ${MINGW_PREFIX}/bin/sip-build \
    --confirm-license \
    --no-make \
    --api-dir=${MINGW_PREFIX}/share/qt6/qsci/api/python \
    --qmake=${MINGW_PREFIX}/bin/qmake6.exe \
    --qmake-setting "CONFIG += ${_build_type}" \
    --qmake-setting "QMAKE_CXXFLAGS=${CXXFLAGS}" \
    --verbose

  make -C build
}

package(){
  cd "${srcdir}"/python-build-${MSYSTEM}
  local _pysite=$(cygpath -u $(${MINGW_PREFIX}/bin/python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"))
  # INSTALL_ROOT is needed for the QtDesigner module, the other Makefiles use DESTDIR
  MSYS2_ARG_CONV_EXCL="${_pysite}" \
  make DESTDIR="${pkgdir}" INSTALL_ROOT="${pkgdir}" install -C build

  # compile Python bytecode
  ${MINGW_PREFIX}/bin/python -m compileall -o 0 -o 1 -d / "${pkgdir}"${MINGW_PREFIX}/lib

  install -Dm644 LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
